package customer.web.beans;

import java.io.Serializable;

import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import customer.ejb.eaos.PersonalizedTPInterface;
import customer.ejb.eaos.PredefinedTPFiltered;
import customer.ejb.eaos.PredefinedTPOffer;
import dtos.HotelDTO;
import dtos.InvitationDTO;
import dtos.PersonalizedTPDTO;
import dtos.PredefinedTPDTO;
import dtos.UserDTO;

@ManagedBean(name="tableBean")
@ViewScoped
public class TableBean implements Serializable {  
    
    private final static Logger logger = Logger.getLogger(TableBean.class.getName());  
     
    @EJB
    private PredefinedTPOffer ptpOffer;     
    private PredefinedTPDTO selectedTravel; 
	private DataModel<PredefinedTPDTO> _model;
	
	@EJB
	private PredefinedTPFiltered predefinedListFiltered;
	private String from;
	private String to;
	
	private int invitationCode;
	@EJB
	private PersonalizedTPInterface personalizedTPInterface;
	private PersonalizedTPDTO travelCorrespondingToInvitation;
	
	private String mailAddress;
    

    @PostConstruct
	public void refresh()
	{
		List<PredefinedTPDTO> c = new LinkedList<>();
		for(PredefinedTPDTO p : ptpOffer.getPredefinedTPOffer())
			c.add(p);
		_model = new ListDataModel<>(c);
	}
	
      
    private void create(){
    	ptpOffer.add(selectedTravel);
    }
    
    public PredefinedTPDTO getSelectedTravel() {  
        return selectedTravel;  
    }  
  
    public void setSelectedTravel(PredefinedTPDTO selectedTravel) {  
        this.selectedTravel = selectedTravel;  
    }  
    

	public DataModel<PredefinedTPDTO> getModel()
	{

		return _model;
	
	}
	
	public void refreshList(){
		
		List<PredefinedTPDTO> c = new LinkedList<>();
		for(PredefinedTPDTO p : predefinedListFiltered.getTravelList(from,to)){
			c.add(p);
		}
		_model = new ListDataModel<>(c);
		
	}
	
	public String getFrom(){
		return from;
	}
	
	public void setFrom(String from){
		this.from = from;
	}
	
	public String getTo(){
		return to;
	}
	
	public void setTo(String to){
		this.to = to;
	}
	
	public int getInvitationCode(){
		return invitationCode;
	}
	
	public void setInvitationCode(int invitationCode){
		this.invitationCode = invitationCode;
	}
	
	public String getMailAddress(){
		return this.mailAddress;
	}
	public void setMailAddress(String mailAddress){
		this.mailAddress = mailAddress;
	}
	public void displayInvitation(){

		travelCorrespondingToInvitation = personalizedTPInterface.getPersonalizedTP(mailAddress,invitationCode);

		
	}
	
	public void displayInvitationCustomer(String invited){

		travelCorrespondingToInvitation = personalizedTPInterface.getPersonalizedTP(invited,invitationCode);

		
	}
	
	
	public PersonalizedTPDTO getTravelCorrespondingToInvitation(){
		return travelCorrespondingToInvitation;
	}


}  